package cn.jly.json.fastjson;

import com.alibaba.fastjson.JSON;

import java.util.Arrays;
import java.util.HashMap;
import java.util.UUID;

/**
 * @author lanyangji
 * @create 2020/9/6 21:22
 */
public class FastJsonTest {
    private static Person person;

    static {
        person = new Person();
        person.setId(UUID.randomUUID().toString());
        person.setName("张三");
        person.setEmail("zhangsan@qq.com");
        person.setSalary(200000d);

        final HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("bobby", "basketball");
        map.put("height", 178d);
        map.put("loveFruit", Arrays.asList("apple", "banana"));
        person.setProperties(map);

        System.out.println("person = " + person);
    }

    public static void main(String[] args) {
        final String personJsonStr = JSON.toJSONString(person);
        System.out.println("personJsonStr = " + personJsonStr);

        final Person person = JSON.parseObject(personJsonStr, Person.class);
        System.out.println("person = " + person);
    }
}
